<?php

namespace Home\Controller;

class ProjectController extends BaseController {

    /**
     * 项目列表
     */
    public function index(){
        $comapny = $this->member();
        $this->assign('user',$comapny);
        $this->display();
    }
    
    /**
     * ajaxmember
     */
    public function ajaxmember(){
        $uid = session('admin_id');
        $sid = I('post.speed');
        $jid = I('post.join');
        $where = array();
        $pid =array();
        if($jid ==1){
            $where[] = "p.total_ren='".addslashes($uid)."'";
        }
        if($jid ==2){
            $sql = "SELECT product_id FROM setpm WHERE find_in_set($uid, `join`)";
            $join = M('')->query($sql);
            if($join){
                foreach ($join as $key=>$val){
                    $pid[] = $val['product_id'];
                }
            }else{
                //一旦setpm表中没有找到数据，则任意定where条件,使数据找不到
                $ui = '1.11';
                $where[] = "p.id='".addslashes($ui)."'";
            } 
        }
        if($pid){
            $pid = implode(',',$pid);
            $where[] = "p.id IN({$pid})";
        }
        if($sid && $sid != 0){
            $where[] = "p.speed='".addslashes($sid)."'";
        }
        $where = implode(' AND ', $where);
        $Model = M('project');
        $data = $Model->alias('p')
                      ->field('p.*,a.name as username')
                      ->join('admin a ON a.admin_id=p.total_ren')
                      ->where($where)
                      ->order('p.id desc')
                      ->select();
        $speed = C('speed');
        $this->assign('sid',$sid);
        $this->assign('data',$data);
        $this->assign('speed',$speed);
        $this->display();
    }
    
    /**
     * 项目详情页
     */
    public function detail(){
        $pid = I('get.pid');
        if(!$pid){
            exit(json_encode(array('errNo'=>1,'msg'=>'项目ID有误或不存在')));
        }
        $data = M('project')->where(array('id'=>$pid))->find();
       // $hour = timediff(time(),strtotime($data['p_start']));//获取两个日期的小时数。
        $day = day($data['p_start']);
        $data['username'] = M('admin')->field('name,admin_id')->where(array('admin_id'=>$data['total_ren']))->find();
        $speed = C('speed');
       // $timediff = timediff($data['p_start'], date("Y-m-d h:i:s"));
        $comapny = $this->member();
       // $users = $this->searchuser($pid);
        $task = M('task')->where(array('pid'=>$pid))->order("tid desc")->select();
        $count['count'] = count($task);
        $count['ok']=0;
        $count['no']=0;
        $count['y']=0;
        foreach ($task as $key=>$val){
            if($val['status']==4){
                $count['ok']++;
            }
            if($val['status']!=4){
                $count['no']++;
            }
            if(time() > strtotime($val['t_stop']) && $val['status'] != 4){
                $count['y']++;
            }
        }
        /* if($users){
            $this->assign('users',$users);
        } */
       
        $this->assign('count',$count);
        $this->assign('task',$task);
        $this->assign('user',$comapny);
        $this->assign('day',$day);
        $this->assign('speed',$speed);
        $this->assign('data',$data);
        $this->assign('pid',$pid);
        $this->display();
    }
    
    /**
     * ajaxplog项目日志
     */
    public function ajaxplog(){
        $pid = I('post.pid');
        $productlog = M('product_log')
                        ->field('product_log.*,a.name')
                        ->join('admin a on a.admin_id = product_log.admin_id ')
                        ->where(array('pid'=>$pid))->select();
        $this->assign('productlog',$productlog);
        $this->display();
    }
    
    /**
     * ajax子任务
     */
    public function ajaxtask(){
        $pid = I('post.pid');
        $type = I('post.status');
        $where = array();
        $where[] = "pid='".addslashes($pid)."'";
        if($type != 0){
            $where[] = "type='".addslashes($type)."'";
        }
        $where = implode(' AND ', $where);
        
        $task = M('task')->where($where)->select();
        $user = M('admin')->getField('admin_id,name');
        $task_status['type'] = C('type');
        $task_status['priority'] = C('priority');
        $task_status['severity'] = C('severity');
        $task_status['status'] = C('status');
       
        $this->assign('user',$user);
        $this->assign('pid',$pid);
        $this->assign('task_status',$task_status);
        $this->assign('task',$task);
        $this->display();
    }
     
    /**
     * 查询项目 相关人员
     */
/*     public function searchuser($pid){
        $people = M('setpm')->field('examine,edit,implement')->where(array('product_id'=>$pid))->find();
        if($people){
            $Model = M('admin');
            $eng['admin_id'] = array('in',$people['examine']);
            $users['examine'] = $Model->field('admin_id,name')->where($eng)->select();
            $project_office['admin_id'] = array('in',$people['edit']);
            $users['edit'] = $Model->field('admin_id,name')->where($project_office)->select();
            $supervisor['admin_id'] = array('in',$people['implement']);
            $users['implement'] = $Model->field('admin_id,name')->where($supervisor)->select();
            return $users;
        }
    } */
    
    /**
     * 保存项目
     */
    public function saveproduct(){
        $data = I('post.');
        $Model = M('project');
        $name = session('admin')['name'];
        if($data){
            $data['add_time'] = time();
            if($data['status']==2){
                $re = $Model->where(array('id'=>$data['id']))->save($data);
                if($re){
                    productLog("修改了".$data['name']."项目",$data['id']);
                    adminLog("修改了".$data['name']."项目",__ACTION__);
                    exit(json_encode(array('errNo'=>0,'msg'=>'修改项目成功')));
                }else{
                    exit(json_encode(array('errNo'=>1,'msg'=>'修改项目失败')));
                }
            }else{
                $res = $Model->where(array('code'=>$data['code']))->find();
                if($res){
                    exit(json_encode(array('errNo'=>1,'msg'=>'项目代码已存在')));
                }
                $ress = $Model->add($data);
                if($ress){
                    productLog("创建了".$data['name']."项目",$ress);
                    adminLog("创建了".$data['name']."项目",__ACTION__);
                    $c[] = $data['total_ren'];
                    SendMessage($c,'设置项目',$name.'把你设置为'.$data['name'].'项目的负责人');
                    exit(json_encode(array('errNo'=>0,'msg'=>'创建项目成功')));
                }else{
                    exit(json_encode(array('errNo'=>1,'msg'=>'创建项目失败')));
                }
            }
        }
    }
    
    /**
     * 获取人员
     */
    public function member(){
        $cor = M('company_cat');
        $company = $cor->field('cat_id,cat_name')->where('parent_id=0')->select();
        $admin =  M('admin')->field('admin_id,post,name,company')->select();
        foreach ($company as $key=>$val){
            foreach ($admin as $k=>$v){
                if($val['cat_id'] == $v['company']){
                    $company[$key]['user'][] = $v;
                }
            }  
            if($company[$key]['user']==null){
                unset($company[$key]);
            }
        }
        return $company;
    }
    
    /**
     * 设置项目人员
     */
    public function ajaxsetpm(){
        $id = I('post.id');
        if($id){
            $setpm = M('setpm')->where(array('product_id'=>$id))->find();
            if($setpm){
                $setpm = explode(',',$setpm['join']);
                $this->assign('setpm',$setpm);
            }
        }
        $user = $this->member();
        $this->assign(array(
            'user'=>$user,
            'id' => $id
        ));
        $this->display();
    }
    
    /**
     * 保存设置人员
     */
    public function savesetpm(){
        $da = I('post.');
        $mo = M('setpm');
       if($da){
           if(!$da['id']){
               exit(json_encode(array('errNo'=>1,'msg'=>'项目ID有误')));
           }else{
               $data['product_id'] = $da['id'];
           }
           $a = $da['eng'];
           //$b = $da['project_office'];
          // $c = $da['supervisor'];
           //$jo = array_merge($a,$b,$c);
           $joi = array_unique($a);
           $data['join'] = implode(',',$joi);
          // $data['examine'] = implode(',',$da['eng']);
          // $data['edit'] = implode(',',$da['project_office']);
          // $data['implement'] = implode(',',$da['supervisor']);
           $data['add_time'] = time();
           if($da['status']=='add'){
               $res = $mo->add($data);
               if($res){
                   productLog('设置项目人员',$pid);
                    adminLog("设置".$da['id']."项目人员",__ACTION__);
                   $u = session('admin');
                   $prname = M('project')->field('name')->where('id='.$data['product_id'])->find();
                   SendMessage($joi,"项目人员设置",$u['name'].'把你加入了'.$prname['name'].'项目');
                   exit(json_encode(array('errNo'=>0,'msg'=>'设置成功')));
               }else{
                   exit(json_encode(array('errNo'=>1,'msg'=>'设置失败')));
               }
           }
           if($da['status']=='edit'){
               $r = $mo->field('join')->where(array('product_id'=>$da['id']))->find();
               $ress = $mo->where(array('product_id'=>$da['id']))->save($data);
               if($ress){
                   productLog('重新设置了项目人员',$da['id']);
                   $a = explode(',',$r['join']);
                   $c = array_diff($a,$joi);
                   $d = array_diff($joi,$a);
                   $u = session('admin');
                   $pnm = M('project')->field('name')->where('id='.$da['id'])->find();
                   if(!empty($c)){
                       SendMessage($c,"移除项目",$u['name'].'把你移除出了'.$pnm['name'].'项目');
                   }
                   if(!empty($d)){
                       SendMessage($d,"项目人员编辑",$u['name'].'在重新修改了'.$pnm['name'].'项目'.',并把你加入了此项目');
                   }
                   adminLog("重新设置了".$da['id']."项目人员",__ACTION__);
                   exit(json_encode(array('errNo'=>0,'msg'=>'重设成功')));
               }else{
                   exit(json_encode(array('errNo'=>1,'msg'=>'重置失败')));
               }
           }
       }
    }
    
    /**
     * 获取任务的指派人和审核人
     */
/*     public function xuser(){
        $pid = session('pid');
        if(!is_numeric($pid)){
            exit(json_encode(array('errNo'=>1,'msg'=>'项目id不能为空')));
        }
        $data = M('process_data')->field('examine_id,eid')->where(array('typeid'=>2,'pid'=>$pid))->select();
        if(empty($data)){
            exit(json_encode(array('errNo'=>1,'msg'=>'未在定义流程中设置指派人或审核人')));
        }
        foreach ($data as $key=>$val){
            if($val['eid']==5){
                $a = M('admin')->field('name,admin_id')->where('admin_id='.$val['examine_id'])->find();
            }
            if($val['eid']==6){
                $b = M('admin')->field('name,admin_id')->where('admin_id='.$val['examine_id'])->find();
            }
        }
        if($a && $b){
            $user['appoint'] = $a;
            $user['trial'] = $b;
            exit(json_encode(array('errNo'=>0,'msg'=>$user)));
        }
        
    } */
    
    
    /**
     * 保存任务
     */
    public function savetask(){
        $data = I('post.');
        $user = session('admin');
        $pid = session('pid');
        if(!is_numeric($pid)){
            exit(json_encode(array('errNo'=>1,'msg'=>'项目id不能为空')));
        }
        $data['add_time'] = time();
        $data['describe'] = json_encode($data['describe']);
        $data['cfrom'] = $user['name'];
        $data['pid'] = $pid;
        $aname =  $data['assigname'];
        $res = M('task')->add($data);
        $assign[] = $data['assign'];
        if($res){
            productLog("下发了".$data['name']."任务给".$aname,$data['pid']);
            taskLog("下发了".$data['name']."任务给".$aname,$res);
            SendMessage($assign,$data['name'],$user['name'].'下发了'.$data['name'].'任务给你');
            adminLog("下发了".$data['name']."任务给".$aname,__ACTION__);
            exit(json_encode(array('errNo'=>0,'msg'=>'下发成功')));
        }else{
            exit(json_encode(array('errNo'=>1,'msg'=>'下发失败')));
        }
    }
    
    /**
     * 任务详情页
     */
    public function task(){
        $tid = I('get.tid');
        $pid = session('pid');
        $uid = session('admin_id');
        if(!$tid || !$pid){
           $this->error('数据错误,请重试');
        }
        
        $task = M('task')->where(array('tid'=>$tid))->find();//查询任务详情
        $rw = M('task_log')->where(array('tid'=>$tid))->select();//查询任务日志
        //$hour = timediff(time(),strtotime($data['p_start']));
        $file_cid = 0;
        //查询在文件分类中是否创建了任务附件文件夹
        if($task['type'] != 3 && $task['status'] != 4){
            $file_cid = M('file_cat')->field('id')->where(array('pid'=>$pid,'type'=>4))->find();
            if(empty($file_cid)){
                $data['name'] = '任务附件';
                $data['pid'] = $pid;
                $data['add_time'] = time();
                $data['type'] =4;
                $file_cid = M('file_cat')->add($data);
            }else{
                $file_cid = $file_cid['id'];
            }
        }

        //已上传附件之后的相关查询
        if($task['status'] == 7){
            $enclosure = M('file_download')->where(array('tid'=>$tid))->select();
            $remarks = M('task_audit')->where(array('tid'=>$tid,'status'=>3))->order('id desc')->find();
            if(!empty($enclosure)){
                $this->assign('enclosure',$enclosure);
            }
            if(!empty($remarks)){
                $this->assign('remarks',$remarks);
            }
        }
        //被驳回的相关查询
        if($task['status'] == 5){
            $enclosure = M('file_download')->where(array('tid'=>$tid))->select();
            $remarks = M('task_audit')->where(array('tid'=>$tid,'status'=>1))->order('id desc')->find();
            if(!empty($enclosure)){
                $this->assign('enclosure',$enclosure);
            }
            if(!empty($remarks)){
                $this->assign('remarks',$remarks);
            }
        }
        //任务完成的相关查询
        if($task['status'] == 4){
            $enclosure = M('file_download')->where(array('tid'=>$tid))->select();
            $remarks = M('task_audit')->where(array('tid'=>$tid,'status'=>2))->order('id desc')->find();
            $remark = M('task_audit')->where(array('tid'=>$tid,'status'=>3))->order('id desc')->find();
            if(!empty($enclosure)){
                $this->assign('enclosure',$enclosure);
            }
            if(!empty($remarks)){
                $this->assign('remarks',$remarks);
            }
            if(!empty($remark)){
                $this->assign('remark',$remark);
            }
        }
        
        $task_status['type'] = C('type');
        $task_status['priority'] = C('priority');
        $task_status['status'] = C('status');
        $this->assign('task_status',$task_status);
        $this->assign('task',$task);
        $this->assign('rw',$rw);
        $this->assign('file_cid',$file_cid);
        $this->display();
    }
    
    /**
     * 成果审核页
     */
    public function achie(){
        $dtid = I('get.dtid');//当前任务的ID
        $tid = I('get.tid');//所在成果任务的ID
        $uid = session('admin_id');
        
        $task = M('task')->where(array('tid'=>$tid))->find();
        $rw = M('task_log')->where(array('tid'=>$tid))->select();
        
        $remark = M('task_audit')->where(array('tid'=>$tid,'status'=>3))->order('id desc')->find();
        if(!empty($remark)){
            $this->assign('remark',$remark);
        }
        //待审批
        if($task['status'] == 7){
            $enclosure = M('file_download')->where(array('tid'=>$tid))->select();
            if(!empty($enclosure)){
                $this->assign('enclosure',$enclosure);
            }
        }
        //被驳回
        if($task['status'] == 5){
            $enclosure = M('file_download')->where(array('tid'=>$tid))->select();
            $remarks = M('task_audit')->where(array('tid'=>$tid,'status'=>1))->order('id desc')->find();
            if(!empty($enclosure)){
                $this->assign('enclosure',$enclosure);
            }
            if(!empty($remarks)){
                $this->assign('remarks',$remarks);
            }
        }
        //已完成
        if($task['status'] == 4){
            $enclosure = M('file_download')->where(array('tid'=>$tid))->select();
            $remarks = M('task_audit')->where(array('tid'=>$tid,'status'=>2))->order('id desc')->find();
            if(!empty($enclosure)){
                $this->assign('enclosure',$enclosure);
            }
            if(!empty($remarks)){
                $this->assign('remarks',$remarks);
            }
        }
        
        $task_status['type'] = C('type');
        $task_status['priority'] = C('priority');
      //  $task_status['severity'] = C('severity');
        $task_status['status'] = C('status');
        $this->assign('task_status',$task_status);
        $this->assign('task',$task);
        $this->assign('dtid',$dtid);
        $this->assign('rw',$rw);
        $this->display();
    }
    
    /**
     * 成果审核成功或驳回的操作
     */
    public function achieok(){
        $status = I('post.status');
        $tid = I('post.tid');
        $dtid = I('post.dtid');
        $remarks = I('post.remarks');
        $time = time();
        $Modal = M('task');
        if(!is_numeric($tid) || !is_numeric($dtid) || !is_numeric($status)){
            exit(json_encode(array('errNo'=>1,'msg'=>'ID有误')));
        }
        
        $data['tid'] = $tid;
        $data['uid'] = session('admin_id');
        $data['remarks'] = $remarks;
        $data['add_time'] = time();
        if($status ==1){
            $data['status'] = 2;
            $res = M('task_audit')->add($data);
            if($res){
                $Modal->where('tid='.$dtid)->save(array('status'=>4,'time_stop'=>$time));
                $Modal->where('tid='.$tid)->save(array('status'=>4,'time_stop'=>$time));
                exit(json_encode(array('errNo'=>0,'msg'=>'已通过')));
            }else{
                exit(json_encode(array('errNo'=>1,'msg'=>'通过失败')));
            }
        }else{
            $data['status'] = 1;
            $res = M('task_audit')->add($data);
            if($res){
                $Modal->where('tid='.$dtid)->save(array('status'=>4,'time_stop'=>$time));
                $Modal->where('tid='.$tid)->save(array('status'=>5,'time_stop'=>$time));
                $assign = $Modal->field('assign')->where('tid='.$tid)->find();
                if($assign['assign'] != ''){
                    $s[] = $assign['assign'];
                    SendMessage($s,'成果任务被驳回',$tid.'号成果任务被驳回,请到任务状态列表--指派给我的任务中查看');
                }
                exit(json_encode(array('errNo'=>0,'msg'=>'已驳回')));
            }else{
                exit(json_encode(array('errNo'=>1,'msg'=>'驳回失败')));
            }
        }
       
    }

    
    /**
     * 下发任务审核（提交）
     */
    public function task_audit(){
        $file_cid = I('post.file_cid');
        $tid = I('post.tid');
        $remarks = I('post.remarks');
        $data = I('post.');
        if(!is_numeric($tid) || !is_numeric($file_cid)){
            exit(json_encode(array('errNo'=>1,'msg'=>'ID有误')));
        }
        $num = M('file_download')->where(array('tid'=>$tid,'file_cid'=>$file_cid))->count();
        if(!$num){
            exit(json_encode(array('errNo'=>1,'msg'=>'请先上传附件')));
        }
        unset($data['file_cid']);
        $data['uid'] = session('admin_id');
        $data['status'] = 3;
        $data['add_time'] = time();
        $res = M('task_audit')->add($data);
        M('task')->where('tid='.$tid)->save(array('status'=>7));
        $this->ftask($tid);
        if($res){
            exit(json_encode(array('errNo'=>0,'msg'=>'上交成功')));
        }else{
            exit(json_encode(array('errNo'=>1,'msg'=>'上交失败')));
        }
    }
    
    /**
     * 发送任务和站内信
     */
    public function ftask($tid){
        $data = M('task')->where('tid='.$tid)->find();
        $a['pid'] = $data['pid'];
        $a['type'] = $data['type'];
        $a['priority'] = 1;
        $a['severity'] = 0;
        $a['t_stop'] = date("Y-m-d H:i:s",strtotime("+1 day"));
        $a['add_time'] = time();
        $a['status'] = 8;
        $a['assigname'] = '自己(我)';
        $a['cfrom'] = session('admin')['name'];
        $a['link'] = $tid .','. achie;
        $a['assign'] = $data['trial'];
        $a['describe'] = $data['name'].'完成情况审核';
        $a['name'] = $data['name'].'完成情况审核';
        $d = task($a);
        taskLog("下发了编制".$tid."号任务",$d);
        $s[] = $data['trial'];
        SendMessage($s,$tid.'号任务','你有任务完成情况审核,请到任务状态列表--待我审查任务中查看');
    }
    
    /**
     * 我的任务
     */
    public function mtask(){
        $uid = session('admin_id');
        $pid = session('pid');
        $role = session('role');
        if($pid){
           /* $sql = "SELECT * FROM task WHERE find_in_set($uid, `assign`)";
           $assin = M('')->query($sql); */
           $assin = M('task')->where(array('pid'=>$pid,'assign'=>$uid))->select();
           $count['count'] = count($assin);
           $count['ok'] =0;
           $count['no'] =0;
           $count['yw'] =0;
           foreach ($assin as $key=>$val){
               if($val['status']==4 || $val['status'] == 5){
                   $count['ok']++;
               }
               if($val['status']!=4  && $val['status'] !=5){
                   $count['no']++;
               }
               if(time() > strtotime($val['t_stop']) && $val['status'] != 4){
                   $count['yw']++;
               }
           }
           
           //获取相关用户
           $setpm = M('setpm')->field('join')->where(array('product_id'=>$pid))->find();
           if($setpm['join']){
               $map['admin_id'] = array('in',$setpm['join']);
               $user = M('admin')->field('admin_id,name')->where($map)->select();
           }
        }
        if($role ==1){
            $project = M('project')->select();
            $pcount['count'] = count($project);//项目总数量
            $pcount['ok'] =0;//已完成项目
            $pcount['no'] =0;//未完成项目
            $pcount['yw'] =0;//延误项目
            foreach ($project as $k=>$v){
                if($v['speed'] == 2){
                    $pcount['ok']++;
                }
                if($v['speed'] == 1){
                    $pcount['no']++;
                }
                if(time() > strtotime($v['p_stop']) && $v['speed'] != 2){
                    if($v['speed'] !=1){
                        $pcount['yw']++;
                    }
                }
            }
             
            //任务总数状态（针对所有项目）
            $task = M('task')->select();
            $tcount['count'] = count($task);
            $tcount['ok'] =0;
            $tcount['no'] =0;
            $tcount['yw'] =0;
            foreach ($task as $ke =>$ve){
                if($ve['status'] == 4 || $ve['status'] == 5){
                    $tcount['ok']++;
                }
                if($ve['status'] != 4 && $ve['status'] !=5){
                    $tcount['no']++;
                }
                if(time() > strtotime($ve['t_stop']) && $ve['status'] != 4 && $ve['status'] !=5){
                    $tcount['yw']++;
                }
            }
            
            $this->assign('pcount',$pcount);
            $this->assign('tcount',$tcount);
        }
        

        $this->assign('user',$user);
        $this->assign('count',$count);
        $this->display();
    }
    
    /**
     * ajax我的任务
     */
    public function ajaxmtask(){
        $user = session('admin');
        $uid = $user['admin_id'];
        $sid = I('post.sid');
        $Modal = M('task');
        if($sid == 1){
           /*  $map['assign'] = array('eq',$uid);
            $map['type'] = array('neq',3);
            $map['status'] = array('neq',8); */
            //$sql = "SELECT * FROM task WHERE find_in_set($uid, `assign`) AND type != 5";
          /*   $assign = $Modal->where($map)->select();   */
            
            $sql = "SELECT * FROM task WHERE assign = $uid AND (type = 1 OR type = 2) AND (status = 2 OR status = 5 OR status = 7 )";
            $assign = M()->cache(true)->query($sql); 
        }
        
         if($sid==2){
             $use = M('admin')->getField('admin_id,name');
             $map['cfrom'] = array('eq',$user['name']);
             $map['type'] =array('neq',3);
             $map['link'] = array('eq','');
             $assign = M('task')->where($map)->select();
         } 
        
        if($sid == 3){
             $sql = "SELECT * FROM task WHERE assign = $uid  AND status = 8";
             $assign = M()->cache(true)->query($sql);
        }
        
        if($sid == 4){
            $map['assign'] = array('eq',$uid);
            $assign = $Modal->where($map)->select();
        }
        
        if($sid == 5){
           /*   $sql = "SELECT * FROM task WHERE assign = $uid AND (status=4 OR status=5) group by name";
            $assign = M()->cache(true)->query($sql); dump($assign);exit; */
            $assign = $Modal->where(array('assign'=>$uid,'status'=>4))->order('tid desc')->select();
                //建立一个目标数组 去重
                $res = array();
                $key = 'name';
                foreach ($assign as $value) {
                    //查看有没有重复项
                    if(isset($res[$value[$key]])){
                        //有：销毁
                        unset($value[$key]);
                    }
                    else{
                        $res[$value[$key]] = $value;
                    }
                }
             $assign = $res;
        }
        $name = M('project')->field('id,name')->select();
        foreach ($assign as $key=>$val){
            foreach($name as $k=>$v){
                if($val['pid']==$v['id']){
                    $assign[$key]['pname'] = $v['name'];
                }
                $d = explode(',',$val['link']);
                $assign[$key]['link1'] = $d[0];
                $assign[$key]['link2'] = $d[1];
            }
        }
        $task_status['type'] = C('type');
        $task_status['priority'] = C('priority');
       // $task_status['severity'] = C('severity');
        $task_status['status'] = C('status');
        $this->assign('task_status',$task_status);
        $this->assign('name',$user['name']);
        $this->assign('assign',$assign);
        $this->assign('uid',$uid);
        $this->assign('sid',$sid);
        $this->assign('use',$use);
        $this->display();
    }
    
}